﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dack_Web2.DTO;
using System.Data.OleDb;

namespace Dack_Web2.DAO
{
    public class GioHangDAO
    {
        public void Insert(GioHangDTO tmp)
        {            
            string str = "insert into GioHang(MaKhachHang, MaDeal, DiaChiGiaoHang, SoLuong, TinhTrang, SoDienThoai) values (@MaKhachHang, @MaDeal, @DiaChiGiaoHang, @SoLuong, @TinhTrang, @SoDienThoai)";
            OleDbParameter[] para1 = {new OleDbParameter("@MaKhachHang", tmp.MaKhachHang),
                                      new OleDbParameter("@MaDeal", tmp.MaDeal),
                                      new OleDbParameter("@DiaChiGiaoHang", tmp.DiaChiGiaoHang),
                                      new OleDbParameter("@SoLuong", tmp.SoLuong),
                                      new OleDbParameter("@TinhTrang", tmp.TinhTrang),
                                      new OleDbParameter("@SoDienThoai", tmp.SoDienThoai)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str,para1);           
        }

        public void Update(GioHangDTO tmp)
        {
           
            string str = "update GioHang set MaKhachHang=@MaKhachHang, MaDeal=@MaDeal, DiaChiGiaoHang=@DiaChiGiaoHang, SoLuong=@SoLuong, TinhTrang=@TinhTrang, SoDienThoai=@SoDienThoai where MaGioHang=@MaGioHang";
           
            OleDbParameter[] para1 ={ new OleDbParameter("@MaKhachHang", tmp.MaKhachHang),
                                    new OleDbParameter("@MaDeal", tmp.MaDeal),
                                    new OleDbParameter("@DiaChiGiaoHang", tmp.DiaChiGiaoHang),
                                    new OleDbParameter("@SoLuong", tmp.SoLuong),
                                    new OleDbParameter("@TinhTrang", tmp.TinhTrang),
                                    new OleDbParameter("@SoDienThoai", tmp.SoDienThoai),
                                    new OleDbParameter("@MaGioHang", tmp.MaGioHang)};
            Sql_DataProvider.SQL_ExecuteNonQuery(str, para1);          
        }

        public void Delete(GioHangDTO tmp)
        {
            OleDbConnection cn = Sql_DataProvider.SQLConnect();
            string str = "delete from GioHang where MaGioHang=@MaGioHang";
            OleDbCommand cmd = new OleDbCommand(str, cn);

            OleDbParameter para1 = new OleDbParameter("@MaGioHang", tmp.MaGioHang);

            cmd.Parameters.Add(para1);

            cmd.ExecuteNonQuery();

            cn.Close();
        }
    }
}